package com.mfangsoft.zhuangjialong.integration.productcategory.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.productcategory.model.ProductCategoryEntity;
import com.mfangsoft.zhuangjialong.integration.productcategory.service.ProductCategoryService;

@Controller(value="serverclassify")
@RequestMapping("/server")
public class ProductCategoryController {

	@Autowired
	private ProductCategoryService productCategoryService;
	
	
	@RequestMapping(value = "/addproductCategory", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<String> addBuildClass(@RequestBody ProductCategoryEntity productCategoryEntity) {

		ResponseMessage<String> message = new ResponseMessage<>();

		try {
			productCategoryService.addProductCategory(productCategoryEntity);

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}

	
	@RequestMapping(value = "/modifyproductCategory", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<String> modifyBuildClass(@RequestBody ProductCategoryEntity productCategoryEntity) {

		ResponseMessage<String> message = new ResponseMessage<>();

		try {
			productCategoryService.modifyProductCategory(productCategoryEntity);

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}
	
	
	@RequestMapping(value = "/queryproductcategoryall", method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage<List<ProductCategoryEntity>> queryProductCategoryALL(){
		ResponseMessage<List<ProductCategoryEntity>> message = new ResponseMessage<>();

		try {
			
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			
			message.setResult(productCategoryService.queryProductCategoryAll());

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}

	
	@RequestMapping(value = "/queryproductcategory/{type}/{p_id}", method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage<List<ProductCategoryEntity>> queryProductCategoryALL(@PathVariable String  type,@PathVariable Long p_id) {

		ResponseMessage<List<ProductCategoryEntity>> message = new ResponseMessage<>();

		try {
			
			
			if(type.equals("-1")){
				
				type=null;
			}
if(p_id.longValue()==-1){
				
	p_id=null;
			}

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			
			message.setResult(productCategoryService.queryProductCategory(type,p_id));

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}
	
}
